# -*- coding: utf-8 -*-
"""
@Time ： 2021/7/30 13:46
@Auth ： Mr.掌心 2929184523
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：请输入模块功能描述
"""
from PO.pages.base_page import BasePage


class ShopCarPage(BasePage):
    ShopCarPage_locators = {
        '_good_locator': '//a[contains(text(),"Huawei/华为 nova 2s")]',
        '_add_car_locator': '//*[@id="join_cart"]',
        '_quit_alert_locator': '//span[@class="layui-layer-setwin"]/a',
        '_my_car_locator': '//span[text()="我的购物车"]',
        '_check_out_locator': '//a[@class="c-btn"]',
        '_goto_check_out_locator': '//a[text()="去结算"]',
        '_submit_locator': '//button[@class="checkout-submit"]',
        '_orderid_locator': '//p[@class="succ-p"]',
        '_my_orderid_locator': '//a[text()="我的订单"]',
        '_submit_cancel_locator': '//div[@class="layui-layer-btn layui-layer-btn-"]/a[text()="确定"]'
    }

    def to_car_check_out(self):
        self.clickjs(self.ShopCarPage_locators['_good_locator'])
        self.clickjs(self.ShopCarPage_locators['_add_car_locator'])
        self.clickjs(self.ShopCarPage_locators['_quit_alert_locator'])
        self.moveto(self.ShopCarPage_locators['_my_car_locator'])
        self.clickjs(self.ShopCarPage_locators['_check_out_locator'])

    def check_out_order(self):
        self.clickjs(self.ShopCarPage_locators['_goto_check_out_locator'])
        self.clickjs(self.ShopCarPage_locators['_submit_locator'])

    def cancel_order(self, reg):
        text = self.get_ralation_text(self.ShopCarPage_locators['_orderid_locator'], reg)
        self.clickjs(self.ShopCarPage_locators['_my_orderid_locator'])

        self.switchwin()
        self.clickjs(f'//em[text()="{text}"]/../..//a[text()="取消订单"]')
        self.clickjs(self.ShopCarPage_locators['_submit_cancel_locator'])